import Vue from "vue";
window.__popups_instance = {};
class Popups {
  constructor(com) {
    // 获取实例方法
    com.newInstance = (properties = {}) => {
      // 合并属性
      const _props = Object.assign(
        {
          /* 一些默认属性*/
        },
        properties
      );

      // 创建新的Vue实例
      const Instance = new Vue({
        render(h) {
          return h(com, { props: _props });
        },
      });

      // 获取Vue实例 并添加到body上
      const component = Instance.$mount();
      document.body.appendChild(component.$el);

      // 返回实例
      return Instance;
    };

    // 创建实例
    let _instance = window.__popups_instance[com.name];
    _instance = _instance || com.newInstance();
    window.__popups_instance[com.name] = _instance;

    // 返回实例
    return _instance.$children[0];
  }
}

export default Popups;
